<template>
  <div>
    <div class="box">
      <el-table border :data="tableData">

        <el-table-column label="用户ID" align="center" prop="userId" />
        <el-table-column label="总费用" align="center" prop="moneySum" />
        <el-table-column label="优惠说明" align="center" prop="discountDesc" />
        <el-table-column label="优惠金额" align="center" prop="discountMoney" />
        <el-table-column label="应付金额" align="center" prop="payMoney" />
        <el-table-column
          label="微信支付截图"
          align="center"
          prop="wxpayImage"
          width="110"
        >
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.wxpayImage"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column
          label="对公转账截图"
          align="center"
          prop="turnImage"
          width="110"
        >
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.turnImage"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="支付码" align="center" prop="payCode" />
        <el-table-column label="支付码来源" align="center" prop="payCodeFrom" />
        <el-table-column
          label="审核人结果"
          align="center"
          :formatter="formatterStatus"
          prop="verifyResult"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button 
              size="mini"
              type="primary"
              icon="el-icon-s-custom"
              :disabled="scope.row.verifyResult !=0 "
              @click="handleAudit(scope.row)"
            >
              审核
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div style="margin: 10px">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="pageNum"
        :page-sizes="[10, 15, 20, 30]"
        :page-size="pageSize"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      ></el-pagination>
    </div>
    <div>
      <!-- 添加或修改用户会员申请对话框 -->
      <el-dialog :visible.sync="dialogVisible" width="600px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="申请人昵称" label-width="100px" prop="userId">
            <el-input v-model="form.nickName" placeholder="" :disabled="true" />
          </el-form-item>

          <el-form-item label="申请人姓名" label-width="100px" prop="userId">
            <el-input v-model="form.realName" placeholder="" :disabled="true" />
          </el-form-item>

          <el-form-item
            label-width="100px"
            label="审核人名字"
            prop="verifyName"
          >
            <el-input
              v-model="form.verifyName"
              placeholder=""
              :disabled="true"
            />
          </el-form-item>

          <el-form-item
            v-if="isOpenVerifyDesc"
            label="审核意见"
            label-width="100px"
            prop="verifyDesc"
          >
            <el-input v-model="form.verifyDesc" type="textarea"></el-input>
            <!-- <el-input v-model="form.verifyDesc" placeholder="请输入审核意见" /> -->
          </el-form-item>

          <el-form-item label="审核人结果" label-width="100px">
            <el-select
              v-model="form.verifyResult"
              placeholder="请选择"
              @change="openverifyDesc"
            >
              <el-option label="通过" value="1"></el-option>
              <el-option label="不通过" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="closeForm">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
  
  <script>
import { applyList, applyVerify, getUserById } from '@/api/news.js'
export default {
  name: 'PayCodePage',
  data() {
    return {
      form: {
        applyId: 0,
        userId: 0,
        nickName: '',
        realName: '',

      },
      dialogVisible: false,
      tableData: [],
      total: 0,
      pageSize: 10,
      pageNum: 1,
      rules: {
        // 表单校验
      },
      isOpenVerifyDesc: false,
      user: null,
    }
  },
  mounted() {
    this.user = JSON.parse(window.sessionStorage.getItem('user'))
    this.loadList()
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          console.log('form', this.form)
          applyVerify(this.form).then((response) => {
            this.$message.success('审核完成')
            this.dialogVisible = false
            this.loadList()
          })
        }
      })
    },
    //检测选框打开意见框
    openverifyDesc() {
      if (this.form.verifyResult == 2) {
        this.isOpenVerifyDesc = true
      } else {
        this.isOpenVerifyDesc = false
      }
    },
    // 取消按钮
    closeForm() {
      this.dialogVisible = false;
    },
    /***加载数据列表 */
    loadList() {
      let param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      }
      applyList(param).then((res) => {
        console.log('applyList', res)
        if (res.code == 200) {
          this.tableData = res.data.records
          this.pageNum = res.data.current
          this.pageSize = res.data.size
          this.total = res.data.total
        }
      })
    },
    /***审核按钮 */
    handleAudit(row) {
      let param = {};
      param.id = row.userId;
      getUserById(param).then(res => {
        console.log('getUserById', res);
        
        if(res.code == 200) {
          this.form.userId = row.userId
          this.form.nickName = res.data.nickName;
          this.form.realName = res.data.realName;
          this.form.applyId = row.applyId
          this.form.verifyName = this.user.realName
          this.form.verifyId = this.user.userId

          this.dialogVisible = true
        }
        else {
          let msg = res.msg;
          this.$message.error(msg);
        }
      });
      //参数



    },

    /***控制页码 */
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNum = val
      this.loadList()
    },

    /**控制每页记录数 */
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.loadList()
    },

    formatterStatus(row) {
      // console.log('formatterStatus', column);
      let stat = '正在审核'
      if (row.verifyResult == 1) {
        stat = '审核通过'
      } else if (row.verifyResult == 2) {
        stat = '审核未通过'
      }
      return stat
    },
  },
}
</script>
  
  <style>
.box {
  margin: 10px;
}
</style>
  